<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ page import="sfmc.biz.vo.Sfmc_TB_MAIN"%>
<%@ page import="sfmc.biz.vo.Sfmc_TB_EMPLOYEE"%>
<%@ page import="java.util.List"%>
<%
String mainList = (String)request.getAttribute("mainList");
Sfmc_TB_MAIN mainData = (Sfmc_TB_MAIN)request.getAttribute("mainData");
List<Sfmc_TB_EMPLOYEE> empList = (List<Sfmc_TB_EMPLOYEE>)request.getAttribute("empList");
String waveUrl = "http://127.0.0.1/wave/";
%>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=IE8" />
<meta http-equiv="Cache-Control" content="No-Cache" />
<meta http-equiv="Pragma" content="No-Cache" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>CallBack</title>
<link rel="stylesheet" type="text/css" href="/resources/theme/metro-blue/easyui.css" />
<link rel="stylesheet" type="text/css" href="/resources/theme/icon.css" />
<link rel="stylesheet" type="text/css" href="/resources/css/ui_custom.css" />
<link rel="stylesheet" type="text/css" href="/resources/css/design.css" />
<link rel="stylesheet" type="text/css" href="/resources/css/form.css" />
<!--[if lt IE 9]>
	<script type="text/javascript" src="/resources/js/html5.js" /></script>
<![endif]-->
<script type="text/javascript" src="/resources/js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="/resources/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="/resources/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/resources/js/jquery.jclock.js"></script>
<script type="text/javascript" src="/resources/js/common.js" /></script>
<script type="text/javascript" src="/resources/js/is.validate.js" /></script>

<script type="text/javascript" language="javascript">
function getList(isClear){
	
	if(isClear){
		document.form.pageNo.value = 1;
		document.form.pageSize.value = 20;
	}
	document.form.target = "_self";
	document.form.action="/main.do";
	document.form.submit();
}
function getOldList(){
	document.location.href = "/old_file_list.do";
}
function getListEnter(){
	if(event.keyCode != 13){
		return false;
	}else{
		getList();
	}
}

function getExcel(){
	document.form.target = "_self";
	document.form.action="/mainList_excel.do";
	document.form.submit();
}

function openMenu(name){
	
	var url = "";
	var opt = "scrollbars=no, resizable=no, ";
	var width = 0;
	var height = 0;
	
	switch(name){
	
	case "emp" : url = "/emp_list.do"; width=350; height=500;
		break;
	case "customer" : url = "/customer_list.do"; width=760; height=788;
		break;
	case "holiday" : url = "/holiday_list.do"; width=490; height=610;
		break;
	case "workTime" : url = "/option_list.do"; width=330; height=330;
		break;
	case "yearStat" : url = "/yearlyStauts_list.do"; width=790; height=600;
		break;
	case "monthStat" : url = "/monthlyStauts_list.do"; width=790; height=600;
		break;
	case "weekStat" : url = "/weeklyStatus_list.do"; width=790; height=600;
		break;
	case "dayStat" : url = "/daillyStauts_list.do"; width=790; height=600;
		break;
	case "custStat" : url = "/custStatus_list.do"; width=800; height=642;
		break;
	case "empStat" : url = "/empStatus_list.do"; width=1200; height=642;
		break;
	}
	
	var _win = window.open(url,name,opt+"width="+width+",height="+height+",left="+(screen.availWidth-width)/2 + ",top="+(screen.availHeight-height)/2);
	_win.focus();
}
function saveData(ordIdx, ordFilename, empName){
	
	if(document.form.dataEmpIdx.value == "0" || empName != null){
		window.open("<%=waveUrl%>"+ordFilename.substring(0,8)+"/"+ordFilename.replace('_',''), "" ,"width=0,height=0,left=2000,top=2000");
	}else{
		document.form.dataOrdIdx.value = ordIdx;
		document.form.dataOrdFilename.value = ordFilename;
		document.form.target = "behindFrame";
		document.form.action="/main_save.do";
		document.form.submit();
	}
}
function deleteData(){
	
	if(document.form.dataEmpIdx.value == "0"){
		alert("담당자를 선택하세요.");
		return;
	}

	var rows = $('#grid_callback').datagrid('getSelections');

	if(rows.length == 0){
		alert("삭제할 이력을 선택하세요.");
		return;
	}
	
	if(confirm("선택한 이력을 삭제하시겠습니까?")){
		
		var deleteStr = "";
		for(var i= 0 ; i < rows.length ; i++){
			deleteStr += rows[i].ordIdx + "|";
		}
		document.form.dataStr.value = deleteStr;

		document.form.target = "behindFrame";
		document.form.action="/main_delete.do";
		document.form.submit();	
	}
}

function reload(returnVal, type, fileName){
	
	switch(type){
	case "U": 
		window.open("<%=waveUrl%>"+ordFilename.substring(0,8)+"/"+ordFilename.replace('_',''), "" ,"width=0,height=0,left=2000,top=2000");
		break;
	case "D": 
		alert("삭제되었습니다.");
		break;
	}
	document.form.target = "_self";
	document.form.action="/main.do";
	document.form.submit();	
}

</script>
</head>
<!-- <body class="easyui-layout" onLoad="setTimeout('getList()',10000);"> -->
<body class="easyui-layout">
	<form method="POST" name="form">
	<iframe id="behindFrame" name="behindFrame"></iframe>
	<input type="hidden" name="searchOrderIdx" value="<%=mainData.getSearchOrdIdx()%>"/>
	<input type="hidden" name="pageNo" value="<%=mainData.getPageNo()%>">
	<input type="hidden" name="pageSize" value="<%=mainData.getPageSize()%>">
	<input type="hidden" name="dataStr" value="">
	<input type="hidden" name="dataOrdIdx" value="0">
	<input type="hidden" name="dataOrdFilename" value="">
	<div data-options="region:'north',border:false" class="layout_north">

		<div class="easyui-panel" data-options="fit:true" style="overflow:hidden;position:relative">
			
			<div class="wrap_gnb_logo">
				<div class="gnb_logo">
					<img src="/resources/img/logo_header.png" /><span>재활용관리시스템</span>
				</div>
				
			</div>
			<div class="wrap_gnb_side">
				<span class="gnb_side_btn">
					<!-- <span class="logout" title="로그아웃" onclick="location.href='/'">로그아웃</span> -->
				</span>
				<!-- <span class="gnb_user">현재 <b>관리자</b>님이 접속 중입니다.</span> -->
			</div>
			
			<div class="datagrid-header gnb_menu">
		        <a href="javascript:void(0)" class="easyui-menubutton" data-options="menu:'#mm1'">등록</a>
		        <a href="javascript:void(0)" class="easyui-menubutton" data-options="menu:'#mm2'">통계</a>
			</div>
		    <div id="mm1">
		        <div onClick="javascript:openMenu('emp');">담당자 등록</div>
		        <div onClick="javascript:openMenu('customer');" id="mm1_02">고객 등록</div>
		        <div onClick="javascript:openMenu('holiday');">휴일 등록</div>
		        <div onClick="javascript:openMenu('workTime');">근무시간 설정</div>
		    </div>
		    <div id="mm2">
		        <div onClick="javascript:openMenu('yearStat');">년별 통계</div>
		        <div onClick="javascript:openMenu('monthStat');">월별 통계</div>
		        <div onClick="javascript:openMenu('weekStat');">주간별 통계</div>
		        <div onClick="javascript:openMenu('dayStat');">일별 통계</div>
		        <div class="menu-sep"></div>
		        <div onClick="javascript:openMenu('custStat');">업체별 주문현황</div>
		        <div onClick="javascript:openMenu('empStat');">사용자별 확인현황</div>
		    </div>
		</div>
	</div>

	<div data-options="region:'center',border:false">
	
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center',border:false">
				<div class="easyui-panel bb0" data-options="iconCls:'icon-head01',border:false,fit:true,title:'Callback'">
					<table id="grid_callback" class="easyui-datagrid"></table>
							
					<div id="tb_callback" class="datagrid-toolbar wrap_tbl_toolbar">	
						<table class="tbl_inner">	
							<colgroup>
								<col width="85px">
								<col width="217px">
								<col width="60px">
								<col width="75px">
								<col width="65px">
								<col width="270px">
								<col width="65px">
							</colgroup>
							<tr>
								<th>조회기간</th>
								<td>
								    <input name="searchFromDate" class="easyui-datebox" value="<%=mainData.getSearchFromDate()%>" data-options="formatter:myformatter"></input> ~
								    <input name="searchToDate" class="easyui-datebox" value="<%=mainData.getSearchToDate()%>" data-options="formatter:myformatter,parser:myparser"></input>
								</td>
								<th>확인여부</th>
								<td>
									<select name="confirmOrd">
										<option value="" <%=("".equals(mainData.getConfirmOrd())) ? "selected" : "" %>>전체</option>
										<option value="1" <%=("1".equals(mainData.getConfirmOrd())) ? "selected" : "" %>>확인</option>
										<option value="0" <%=("0".equals(mainData.getConfirmOrd())) ? "selected" : "" %>>미확인</option>
									</select>
								</td>
								<th>채널설정</th>
								<td>
									<input type="radio" name="channelNum" value=""<%=("".equals(mainData.getChannelNum())) ? "checked='true'" : "" %>>전체&nbsp;&nbsp;
									<input type="radio" name="channelNum" value="1"<%=("1".equals(mainData.getChannelNum())) ? "checked='true'" : "" %>>1ch&nbsp;&nbsp;
									<input type="radio" name="channelNum" value="2"<%=("2".equals(mainData.getChannelNum())) ? "checked='true'" : "" %>>2ch&nbsp;&nbsp;
									<input type="radio" name="channelNum" value="3"<%=("3".equals(mainData.getChannelNum())) ? "checked='true'" : "" %>>3ch&nbsp;&nbsp;
									<input type="radio" name="channelNum" value="4"<%=("4".equals(mainData.getChannelNum())) ? "checked='true'" : "" %>>4ch
								</td>
								<th>서버설정</th>
								<td>
									<input name="server" type="radio" value="1" checked=true onclick="getList();">신서버&nbsp;&nbsp;
									<input name="server" type="radio" value="2" onclick="getOldList();">구서버&nbsp;&nbsp;
								</td>
							</tr>
							<tr>
								<th>고객전화번호</th>
								<td class="formText"><input type="text" name="searchCallerID" value="<%=mainData.getSearchCallerID()%>" onKeyPress="getListEnter();"></td>
								<th>업체명</th>
								<td colspan="3" class="formText"><input type="text" name="searchCustName" value="<%=mainData.getSearchCustName()%>" onKeyPress="getListEnter();"></td>
								<td colspan="3"><a href="javascript:getList();"class="easyui-linkbutton" data-options="iconCls:'icon-search'">조회</a>
								<a href="javascript:getExcel();" class="easyui-linkbutton" data-options="iconCls:'icon-excel'">엑셀저장</a>
							</tr>
						</table>
					</div>
				</div>
			</div>
			<div data-options="region:'south',border:false">
				<div class="easyui-layout" data-options="fit:true">
				
					<div data-options="region:'north',border:false">
						<div id="pp" class="easyui-pagination">
						</div>
					</div>
					
					<div data-options="region:'center',border:false">
						<div class="easyui-panel combobox-item-selected padding5" data-options="fit:true">
							<table class="tbl_inner">	
						<colgroup>
							<col>
							<col width="90px">
							<col>
						</colgroup>
						<tr>
							<th>담당</th>
							<td>
								<select name="dataEmpIdx">
									<option value="0">선택하세요</option>
<%if(empList != null){
	for(int i = 0 ; i < empList.size() ; i++){
		Sfmc_TB_EMPLOYEE sfmc_TB_EMPLOYEE = empList.get(i);
		
		if(mainData.getDataEmpIdx() == sfmc_TB_EMPLOYEE.getEmpIdx()){
			out.println("<option value='"+sfmc_TB_EMPLOYEE.getEmpIdx()+"' selected>"+sfmc_TB_EMPLOYEE.getEmpName()+"</option>");
		}else{
			out.println("<option value='"+sfmc_TB_EMPLOYEE.getEmpIdx()+"'>"+sfmc_TB_EMPLOYEE.getEmpName()+"</option>");		
		}
	}
}%>
								</select>
							</td>
							<td><a href="javascript:deleteData();" id="deleteBtn" class="easyui-linkbutton" data-options="iconCls:'icon-cut'">삭제</a></td>
						</tr>
					</table>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div data-options="region:'south',border:false" class="layout_south">
		Copyright 2013 Suwon City Facilities Management Corporation.
		<p class="clock">	
			<span id="date"></span>
			<span id="clock"></span>
		</p>
	</div>
	</form>
</body>

<script type="text/javascript">
//캘린더
function myformatter(date){
    var y = date.getFullYear();
    var m = date.getMonth()+1;
    var d = date.getDate();
    return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
}
function myparser(s){
    if (!s) return new Date();
    var ss = (s.split('-'));
    var y = parseInt(ss[0],10);
    var m = parseInt(ss[1],10);
    var d = parseInt(ss[2],10);
    if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
        return new Date(y,m-1,d);
    } else {
        return new Date();
    }
}

//그리드
$('#grid_callback').datagrid({
	rownumbers:true,
    fitColumns: true,
    //singleSelect: true,
    fit: true,
    striped: true,
    toolbar:'#tb_callback',
    //pagination: true,
    nowrap: true,
    data:<%=mainList%>,
    columns:[[
		{field:'num',width:0,hidden:true},
		{field:'ordIdx',width:0,hidden:true},
		{field:'chekbox',width:0,checkbox:true},
		{field:'confirmOrd',title:'상 태',fixed:true,width:70,align:'center'}, 
		{field:'ordDate1',title:'날 짜',fixed:true,width:100,align:'center'},
		{field:'ordDate2',title:'시 간',fixed:true,width:80,align:'center'},
		{field:'callerID',title:'C I D',fixed:true,width:110,align:'center'},
		{field:'custName',title:'주 문 업 체',fixed:true,width:312,align:'center'},
		{field:'channelNum',title:'채 널',fixed:true,width:40,align:'center'},
		{field:'ordFilename',title:'파 일 명',fixed:true,width:180,align:'center'},
		{field:'confirmDate',title:'확 인 일 자',fixed:true,width:160,align:'center'},
		{field:'empName',title:'담 당 자',fixed:true,width:70,align:'center'}
    ]]
}); 


$('#grid_callback').datagrid({
	onDblClickRow:function(rowIndex, row){
		saveData(row.ordIdx, row.ordFilename, row.empName);
	}
});

$('#grid_callback').datagrid({
	onClickRow:function(rowIndex, row){
	}
}); 


function cellStyler(index,row){
    if (row.num < 2){
        return '<span class="grid_error"></span>';
    }
}
function detailLink(val,rec){
	return '<a href="${ctx}/rvhistory/detail">'+val+'</a>';
}
//paging
$('#pp').pagination({
    total:<%=mainData.getTotalCnt()%>,
    pageSize:<%=mainData.getPageSize()%>,
    pageNumber:<%=mainData.getPageNo()%>,
    pageList:[20,30,50]
});
$('#pp').pagination({
	onSelectPage:function(pageNumber, pageSize){
		$(this).pagination('loading');
		document.form.pageNo.value = pageNumber;
		document.form.pageSize.value = pageSize;
		$(this).pagination('loaded');
		getList();
	}
});
</script>
</html>